# -*- coding:utf-8 -*-

# @Time : 2023/3/17 10:28
# @Author : 快乐的小猴子
# @Version : 
# @Function : 

import requests


class SetProxies():

    def get_proxies(self):
        # 提取代理API接口，获取1个代理IP
        api_url = "https://kps.kdlapi.com/api/getkps/?secret_id=o41qghid3pb5kyydo46g&num=1&signature=fl2o1vb2172i4mgwsv3f9kwvebq5gmaw&pt=1&format=&sep=1"
        # 获取API接口返回的代理IP
        proxy_ip = requests.get(api_url).text
        # 用户名密码认证(私密代理/独享代理)
        username = "zczhaod"
        password = "zzcyyt05081129"
        proxies = {
            "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip},
            "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip}
        }
        # print(proxies)
        return proxies
        # 白名单方式（需提前设置白名单）
        # proxies = {
        #     "http": "http://%(proxy)s/" % {"proxy": proxy_ip},
        #     "https": "http://%(proxy)s/" % {"proxy": proxy_ip}
        # }

    # def test_api(self, proxies):
    #     # 使用代理IP发送请求
    #     target_url = 'https://pic.ojbkcdn.com/picture/43443.jpg'
    #     response = requests.get(target_url, proxies=proxies)
    #     print(response.status_code)
    #
    #     if response.status_code == 200:
    #         response.encoding = "utf-8"
    #         print(response.text)


# setproxies = SetProxies()
# proxies = setproxies.get_proxies()
# setproxies.test_api(proxies)
